/*
package com.cn.FeiJingDITui.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.fanwe.VideoShort.douyin.utils.MultiImagePreview.AppConstant;
import com.fanwe.VideoShort.douyin.utils.MultiImagePreview.MultiImagePreviewActivity;
import com.fanwe.hybrid.activity.BaseTitleActivity;
import com.fanwe.hybrid.http.AppRequestCallback;
import com.fanwe.library.adapter.http.model.SDResponse;
import com.fanwe.library.dialog.SDDialogMenu;
import com.fanwe.library.utils.SDToast;
import com.fanwe.live.R;
import com.fanwe.live.adapter.GridViewAdapter;
import com.fanwe.live.common.CommonInterface;
import com.fanwe.live.cos.CosBean;
import com.fanwe.live.cos.QServiceCfg;
import com.fanwe.live.cos.UpLoadImageCosHelper;
import com.fanwe.live.view.MyGridView;
import com.fanwe.utils.JsonUitl;
import com.fanwe.utils.LogUtil;
import com.fanwe.utils.ToastUtil;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoImpl;
import com.jph.takephoto.compress.CompressConfig;
import com.jph.takephoto.model.CropOptions;
import com.jph.takephoto.model.InvokeParam;
import com.jph.takephoto.model.LubanOptions;
import com.jph.takephoto.model.TContextWrap;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.jph.takephoto.model.TakePhotoOptions;
import com.jph.takephoto.permission.InvokeListener;
import com.jph.takephoto.permission.PermissionManager;
import com.jph.takephoto.permission.TakePhotoInvocationHandler;
import com.tencent.cos.xml.exception.CosXmlClientException;
import com.tencent.cos.xml.exception.CosXmlServiceException;
import com.tencent.cos.xml.model.CosXmlRequest;
import com.tencent.cos.xml.model.CosXmlResult;

import org.xutils.view.annotation.ViewInject;

import java.io.File;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

*/
/**
 * Created by shibx on 2016/7/12.  问题反馈界面
 *//*

public class NewLiveServicesActivity extends BaseTitleActivity implements TakePhoto.TakeResultListener, InvokeListener {
    @BindView(R.id.et_question)
    EditText etQuestion;

    @BindView(R.id.tv_number)
    TextView tv_number;
    @BindView(R.id.grid_view)
    MyGridView gridView;


    @BindView(R.id.grid_view1)
    MyGridView gridView1;
    @BindView(R.id.tv_number1)
    TextView tv_number1;

    @ViewInject(R.id.iv_head)
    private ImageView iv_head;// 头像


    @BindView(R.id.select_img_layout)
    LinearLayout selectImgLayout;

    private GridViewAdapter mAdapter;
    private GridViewAdapter mAdapter1;
    //图片本地地址集合
    private ArrayList<String> mlocalPhotoList = new ArrayList<>();
    //图片本地地址集合
    private ArrayList<String> mlocalPhotoList1 = new ArrayList<>();

    //  图片库里面需要的
    private TakePhoto takePhoto;
    private InvokeParam invokeParam;
    //cos上传图片需要的
    private CosBean mCosBean;
    private String fileName;
    private String objectKey;
    private String full_oss_path;

    int sumNumber = 9;

    int type = 0;

    Boolean iscat = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getTakePhoto().onCreate(savedInstanceState);
        setContentView(R.layout.act_services);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        getCos();
        initTitle();
        getTakePhoto();
        mlocalPhotoList = new ArrayList<>();
        mAdapter = new GridViewAdapter(this, mlocalPhotoList, sumNumber);
        gridView.setAdapter(mAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int viewType = mAdapter.getItemViewType(position);
                type = 0;
                if (viewType == 1) {
                    showSelectPictureDialog();
                } else {
                    showPictureActionDialog(position);
                }
            }
        });
        tv_number.setText(1 + "/" + sumNumber);

        mlocalPhotoList1 = new ArrayList<>();
        mAdapter1 = new GridViewAdapter(this, mlocalPhotoList1, sumNumber);
        gridView1.setAdapter(mAdapter1);
        gridView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int viewType = mAdapter1.getItemViewType(position);
                type = 1;
                if (viewType == 1) {
                    showSelectPictureDialog();
                } else {
                    showPictureActionDialog(position);
                }
            }
        });
        tv_number1.setText(1 + "/" + sumNumber);

        iv_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iscat = true;
                showCatSelectPictureDialog();
            }
        });


    }

    private void initTitle() {
        mTitle.setMiddleTextTop("联系客服");
        mTitle.setLeftImageLeft(R.drawable.ic_arrow_left_white);
        mTitle.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }


    */
/**
     * 获得cos配置信息
     *//*


    public void getCos() {
        CommonInterface.requestTXCos(new AppRequestCallback<CosBean>() {
            @Override
            protected void onStart() {
                super.onStart();
                showProgressDialog("");
            }

            @Override
            protected void onSuccess(SDResponse sdResponse) {
                if (actModel.getStatus() == 1) {
                    mCosBean = actModel;
                }
            }

            @Override
            protected void onFinish(SDResponse resp) {
                super.onFinish(resp);
                dismissProgressDialog();
            }
        });
    }


    */
/**
     * 调用联系客服接口
     *//*


    public void requestNote(String note, String imgs) {
        CommonInterface.requestNote(note, imgs, new AppRequestCallback<CosBean>() {
            @Override
            protected void onStart() {
                super.onStart();
                showProgressDialog("");
            }

            @Override
            protected void onSuccess(SDResponse sdResponse) {
                if (actModel.getStatus() == 1) {
                    mCosBean = actModel;
                    dismissProgressDialog();
                    ToastUtil.showShort("反馈成功，我们会尽快解决");
                    finish();
                } else {
                    ToastUtil.showShort(actModel.getShow_err());
                }
            }

            @Override
            protected void onFinish(SDResponse resp) {
                super.onFinish(resp);
                dismissProgressDialog();
            }
        });
    }


    //上传到cos地址拼接
    StringBuilder sb;

    @OnClick(R.id.tv_commit)
    public void onViewClicked() {

        sb = new StringBuilder();
        if (TextUtils.isEmpty(etQuestion.getText().toString().trim())) {
            ToastUtil.showShort("请填写反馈信息");
            return;
        }
        showProgressDialog("接口请求中");
        if (mlocalPhotoList.size() > 0) {
            for (int i = 0; i < mlocalPhotoList.size(); i++) {
                uploadImageCos(mlocalPhotoList.get(i), i);
            }
        } else {
            requestNote(etQuestion.getText().toString().trim(), "");
        }

    }


    private void uploadImageCos(String path, int i) {
        if (mCosBean == null) {
            SDToast.showToast("网络异常");
            getActivity().finish();
            return;
        }
        fileName = System.currentTimeMillis() + ".png";
        objectKey = mCosBean.getDir() + fileName;
        full_oss_path = mCosBean.getDomain() + objectKey;
        Log.d("Debug", "返回的地址是" + full_oss_path);
        new UpLoadImageCosHelper(new QServiceCfg(NewLiveServicesActivity.this, path, mCosBean), fileName, new UpLoadImageCosHelper.UpLoadListener() {
            @Override
            public void onProgress(long progress, long max) {

            }

            @Override
            public void onSuccess(CosXmlRequest request, CosXmlResult result) {
                LogUtil.d("Debug", "上传cos成功" + JsonUitl.objectToString(result));
                if (i < mlocalPhotoList.size() - 1) {
                    sb.append(result.accessUrl + ",");
                } else {
                    sb.append(result.accessUrl);
                }

                //最后一张图片的时候  请求接口
                if (i == mlocalPhotoList.size() - 1) {
                    LogUtil.d("Debug", "拼接的cos地址" + sb);
                    requestNote(etQuestion.getText().toString().trim(), "");
                }

            }

            @Override
            public void onFail(CosXmlRequest cosXmlRequest, CosXmlClientException clientException, CosXmlServiceException serviceException) {
//                SDToast.showToast("上传Cos失败");
                dismissProgressDialog();
            }
        });
    }

    */
/**
     * 拍照和相册中选择
     *//*

    private void showSelectPictureDialog() {
        File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        Uri imageUri = Uri.fromFile(file);
        String[] arrOption = new String[]
                {"相机", "相册"};

        SDDialogMenu dialog = new SDDialogMenu(this);

        dialog.setItems(arrOption);
        dialog.setmListener(new SDDialogMenu.SDDialogMenuListener() {

            @Override
            public void onItemClick(View v, int index, SDDialogMenu dialog) {
                switch (index) {
                    case 0:
                        takePhoto.onPickFromCapture(imageUri);
                        break;
                    case 1:
                        if (type == 0) {
                            takePhoto.onPickMultiple(sumNumber - mlocalPhotoList.size());
                        } else {
                            takePhoto.onPickMultiple(sumNumber - mlocalPhotoList1.size());
                        }
//                        takePhoto.onPickMultipleWithCrop(1, getCropOptions());
                        break;
                    default:
                        break;
                }
                dialog.dismiss();
            }

            @Override
            public void onDismiss(SDDialogMenu dialog) {
            }

            @Override
            public void onCancelClick(View v, SDDialogMenu dialog) {
            }
        });
        dialog.showBottom();
    }


    */
/**
     * 拍照和相册中选择
     *//*

    private void showCatSelectPictureDialog() {
        File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        Uri imageUri = Uri.fromFile(file);
        String[] arrOption = new String[]
                {"相机", "相册"};

        SDDialogMenu dialog = new SDDialogMenu(this);

        dialog.setItems(arrOption);
        dialog.setmListener(new SDDialogMenu.SDDialogMenuListener() {

            @Override
            public void onItemClick(View v, int index, SDDialogMenu dialog) {
                switch (index) {
                    case 0:
                        takePhoto.onPickFromCaptureWithCrop(imageUri, getCropOptions());
                        break;
                    case 1:
                        takePhoto.onPickMultipleWithCrop(1, getCropOptions());
                        break;
                    default:
                        break;
                }
                dialog.dismiss();
            }

            @Override
            public void onDismiss(SDDialogMenu dialog) {
            }

            @Override
            public void onCancelClick(View v, SDDialogMenu dialog) {
            }
        });
        dialog.showBottom();
    }


    */
/**
     * 选中某个item  是删除操作还是查看操作
     *//*

    private void showPictureActionDialog(int position) {
        String[] arrOption = new String[]
                {"查看", "删除"};

        SDDialogMenu dialog = new SDDialogMenu(this);

        dialog.setItems(arrOption);
        dialog.setmListener(new SDDialogMenu.SDDialogMenuListener() {

            @Override
            public void onItemClick(View v, int index, SDDialogMenu dialog) {
                switch (index) {
                    case 0:
                        // 查看
                        if (type == 0) {
                            Intent intent = new Intent(NewLiveServicesActivity.this, MultiImagePreviewActivity.class);
                            intent.putExtra(AppConstant.EXTRA_IMAGES, mlocalPhotoList);
                            intent.putExtra(AppConstant.EXTRA_POSITION, position);
                            intent.putExtra(AppConstant.EXTRA_CHANGE_SELECTED, false);
                            startActivity(intent);
                        } else {
                            Intent intent = new Intent(NewLiveServicesActivity.this, MultiImagePreviewActivity.class);
                            intent.putExtra(AppConstant.EXTRA_IMAGES, mlocalPhotoList1);
                            intent.putExtra(AppConstant.EXTRA_POSITION, position);
                            intent.putExtra(AppConstant.EXTRA_CHANGE_SELECTED, false);
                            startActivity(intent);
                        }

                        break;
                    case 1:
                        if (type == 0) {
                            mlocalPhotoList.remove(position);
                            mAdapter.notifyDataSetChanged();
                            tv_number.setText(mlocalPhotoList.size() + "/" + sumNumber);
                        } else {
                            mlocalPhotoList1.remove(position);
                            mAdapter1.notifyDataSetChanged();
                            tv_number1.setText(mlocalPhotoList.size() + "/" + sumNumber);
                        }
                        break;
                    default:
                        break;
                }
                dialog.dismiss();
            }

            @Override
            public void onDismiss(SDDialogMenu dialog) {
            }

            @Override
            public void onCancelClick(View v, SDDialogMenu dialog) {
            }
        });
        dialog.showBottom();
    }

    */
/**
     * 下面都是  图片库  要实现的方法
     *//*


    */
/**
     * 获取TakePhoto实例
     *
     * @return
     *//*

    public TakePhoto getTakePhoto() {
        if (takePhoto == null) {
            takePhoto = (TakePhoto) TakePhotoInvocationHandler.of(this).bind(new TakePhotoImpl(this, this));
        }
        return takePhoto;
    }

    */
/**
     * 图片压缩操作
     *
     * @param takePhoto
     *//*

    private void configCompress(TakePhoto takePhoto) {
        //压缩大小不超过  多少b
        int maxSize = Integer.parseInt("102400");
        // 压缩宽高
        int width = Integer.parseInt("800");
        int height = Integer.parseInt("800");
        //是否展示压缩进度条
        boolean showProgressBar = false;
        //拍照压缩后是否保存原图
        boolean enableRawFile = true;
        //压缩方式   true为takephoto 自带 false为luban压缩方式
        boolean compressType = true;
        CompressConfig config;
        if (compressType) {
            config = new CompressConfig.Builder().setMaxSize(maxSize)
                    .setMaxPixel(width >= height ? width : height)
                    .enableReserveRaw(enableRawFile)
                    .create();
        } else {
            LubanOptions option = new LubanOptions.Builder().setMaxHeight(height).setMaxWidth(width).setMaxSize(maxSize).create();
            config = CompressConfig.ofLuban(option);
            config.enableReserveRaw(enableRawFile);
        }
        takePhoto.onEnableCompress(config, showProgressBar);
    }


    private void configTakePhotoOption(TakePhoto takePhoto) {
        TakePhotoOptions.Builder builder = new TakePhotoOptions.Builder();
        //使用TakePhoto自带相册
        builder.setWithOwnGallery(true);
//        纠正拍照的照片旋转角度
        builder.setCorrectImage(true);
        takePhoto.setTakePhotoOptions(builder.create());
    }

    private CropOptions getCropOptions() {
        int height = Integer.parseInt("800");
        int width = Integer.parseInt("800");
        //使用 第三方  true  使用takephoto自带 false
        boolean withWonCrop = false;
        CropOptions.Builder builder = new CropOptions.Builder();
        // 宽x高  false   宽比高（相当于比例）true
        boolean isScale = true;
        if (isScale) {
            builder.setAspectX(width).setAspectY(height);
        } else {
            builder.setOutputX(width).setOutputY(height);
        }
        builder.setWithOwnCrop(withWonCrop);
        return builder.create();
    }

    @Override
    public void takeSuccess(TResult result) {
        LogUtil.d("Debug", "takeSuccess：" + JsonUitl.objectToString(result));
        if (result == null) {
            return;
        }
        if (iscat) {
            Glide.with(this)
                    .load(result.getImage().getOriginalPath())
                    .into(iv_head);
            iscat = false;
            return;
        }

        for (int i = 0; i < result.getImages().size(); i++) {
            TImage tImage = result.getImages().get(i);
            if (type == 0) {
                mlocalPhotoList.add(tImage.getOriginalPath());
            } else {
                mlocalPhotoList1.add(tImage.getOriginalPath());
            }

        }

        for (int i = 0; i < mlocalPhotoList.size(); i++) {
            LogUtil.d("Debug", "每个图片地址" + mlocalPhotoList.get(i));
        }
        if (type == 0) {
            mAdapter.notifyDataSetChanged();
            tv_number.setText(mlocalPhotoList.size() + "/" + sumNumber);
        } else {
            mAdapter1.notifyDataSetChanged();
            tv_number1.setText(mlocalPhotoList.size() + "/" + sumNumber);
        }
    }

    @Override
    public void takeFail(TResult result, String msg) {
        LogUtil.d("Debug", "错误信息：" + result.getImage().getCompressPath());
    }

    @Override
    public void takeCancel() {
        LogUtil.d("Debug", "取消掉了");
    }

    @Override
    public PermissionManager.TPermissionType invoke(InvokeParam invokeParam) {
        PermissionManager.TPermissionType type = PermissionManager.checkPermission(TContextWrap.of(this), invokeParam.getMethod());
        if (PermissionManager.TPermissionType.WAIT.equals(type)) {
            this.invokeParam = invokeParam;
        }
        return type;
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionManager.TPermissionType type = PermissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionManager.handlePermissionsResult(this, type, invokeParam, this);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        getTakePhoto().onSaveInstanceState(outState);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        getTakePhoto().onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
    }


}
*/
